package com.example;

import java.util.Arrays;
import java.util.stream.Collectors;

public class LC1_3 {
    public static void main(String[] args) {
        int[] nums = new int[]{-1,-100,3,99};
        int k = 2;
        rotate(nums, k);
        String collect = Arrays.stream(nums).mapToObj(i -> i + "")
                .collect(Collectors.joining(",","[","]"));
        System.out.println(collect);
    }

    public static void rotate(int[] nums, int k) {
        int len = nums.length;
        k = k % len;
        int a = nums[0];
        int i = k;
        int[] visited = new int[len];
        int count = 0;
        while(count < len) {
            if(visited[i] == 0) {
                int temp = a;
                a = nums[i];
                nums[i] = temp;
                visited[i] = 1;
                i = (i+k)%len;
                count++;
            } else {
                i = (i+1+k)%len;
                a = nums[i];
            }

        }
    }
}
